package com.example.lenovo.findmyclass;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.example.lenovo.findmyclass.Buildings.BuildingFour;
import com.example.lenovo.findmyclass.Buildings.BuildingOne;
import com.example.lenovo.findmyclass.Buildings.BuildingThree;
import com.example.lenovo.findmyclass.Buildings.BuildingTwo;
import com.example.lenovo.findmyclass.Menu.AddressBook;
import com.example.lenovo.findmyclass.Menu.PersonalData;
import com.example.lenovo.findmyclass.Menu.Reservation.ReservationClass;

import java.util.Calendar;
import java.util.TimeZone;

public class MainActivity extends Activity {
    private Button building1,building2,building3,building4;
    private Button backToLogin;
    private TextView information,address_book,reservation,map;
    private TextView my_id,my_name;
    public static String userId,userName;
    TextView txtTime1,txtTime2;
    Calendar cal;
    String year,month,day,week,hour,minute;
    String my_time_1,my_time_2;
    private RegisterActivity registerActivity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
       // Dialog dialog = new Dialog(MainActivity.this, R.style.activity_translucent);
        //dialog.setContentView(R.layout.transparent_layout); dialog.show();
        building1 = findViewById(R.id.building1);
        building1.setOnClickListener(new ButtonListener());
        building2 = findViewById(R.id.building2);
        building2.setOnClickListener(new ButtonListener());
        building3 = findViewById(R.id.building3);
        building3.setOnClickListener(new ButtonListener());
        building4 = findViewById(R.id.building4);
        building4.setOnClickListener(new ButtonListener());
        backToLogin = findViewById(R.id.back_to_login);
        backToLogin.setOnClickListener(new ButtonListener());
        txtTime1 = (TextView) findViewById(R.id.text1);
        txtTime2 = (TextView) findViewById(R.id.text2);
        my_name=findViewById(R.id.my_name);
        my_id=findViewById(R.id.my_id);
        my_name.setText(userName);
        my_id.setText(userId);
        information=(TextView) findViewById(R.id.information);
        address_book=findViewById(R.id.address_book);
        reservation=findViewById(R.id.reservation);
        information.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this,PersonalData.class);
                startActivity(intent);
            }
        });
        address_book.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent(MainActivity.this,AddressBook.class);
                startActivity(intent1);
            }
        });

        reservation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent3 = new Intent(MainActivity.this, ReservationClass.class);
                startActivity(intent3);
            }
        });
        cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));

        year = String.valueOf(cal.get(Calendar.YEAR));
        month = String.valueOf(cal.get(Calendar.MONTH)+1);
        week = String.valueOf(cal.get(Calendar.DAY_OF_WEEK));
        if("1".equals(week)){
            week ="天";
        }else if("2".equals(week)){
            week ="一";
        }else if("3".equals(week)){
            week ="二";
        }else if("4".equals(week)){
            week ="三";
        }else if("5".equals(week)){
            week ="四";
        }else if("6".equals(week)){
            week ="五";
        }else if("7".equals(week)){
            week ="六";
        }
        day = String.valueOf(cal.get(Calendar.DATE));
        if (cal.get(Calendar.AM_PM) == 0)
            hour = String.valueOf(cal.get(Calendar.HOUR));
        else
            hour = String.valueOf(cal.get(Calendar.HOUR)+12);
        minute = String.valueOf(cal.get(Calendar.MINUTE));

        my_time_1 = year + "-" + month + "-" + day + " 周"+ week;
        my_time_2 = hour + ":" + minute ;

        txtTime1.setText(my_time_1);
        txtTime2.setText(my_time_2);

    }
    private class ButtonListener implements View.OnClickListener {
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.back_to_login:
                    Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                    startActivity(intent);
                    break;
                case R.id.building1:
                    Intent intent1 = new Intent(MainActivity.this, BuildingOne.class);
                    startActivity(intent1);
                    break;
                case R.id.building2:
                    Intent intent2 = new Intent(MainActivity.this, BuildingTwo.class);
                    startActivity(intent2);
                    break;
                case R.id.building3:
                    Intent intent3 = new Intent(MainActivity.this, BuildingThree.class);
                    startActivity(intent3);
                    break;
                case R.id.building4:
                    Intent intent4 = new Intent(MainActivity.this, BuildingFour.class);
                    startActivity(intent4);
                    break;
            }
        }
    }


}